{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Capital Asset Pricing Model\n",
    "\n",
    "Markowitz-model work fine, BUT we can not get rid of all risk by diversification!\n",
    "\n",
    "_*There are two types of risk:*_\n",
    "1. Unsystematic risk: \"Specific Risk\" - This is the risk specific to individual stocks. It can be diversified away by incresing the number of stocks in the portfolio\n",
    "\n",
    "**Unsystematic Risk is the component of a stock's return that is not correlated with market moves**\n",
    "\n",
    "2. Systematic Risk: \"Market Risk\" - This risk can not be diversified away. For example: interest rates, recession or wat\n",
    "\n",
    "**Capital Risk Pricing Model measures this risk**\n",
    "<hr style=\"height: 3px;\">\n",
    "\n",
    "## Expected Return\n",
    "It was formulated in the early 1960s by Sharpe and his colleagues\n",
    "\n",
    "**Note: ** We use SPY500 as a represention of them arket as a whole\n",
    "\n",
    "\n",
    "$E[r_a] = r_f + \\beta_a(E[r_m]-r_f)$\n",
    "\n",
    "- $E[r_a]$ = The expected return of investment: it may be a single stock or a portfolio *effecient or not it does not matter*\n",
    "\n",
    "- $r_f$ = Base return because of risk-free rate\n",
    "- $\\beta_a(E[r_m]-r_f)$ = Market excess return multiplied by a factor *(beta)*\n",
    "\n",
    "**Linear relationship between any stock expected return and market premium!**\n",
    "\n",
    "$\\beta_a = \\frac{Cov(r_a,r_m)}{Var(r_m)}$\n",
    "\n",
    "- According to **CAPM** *beta* is the only relevant measure of a stock's risk\n",
    "- Measures the stock's relative volatility: how much the price of a given stock goes up/down compared to that of the whole market\n",
    "\n",
    "<hr style=\"height: 3px;\">\n",
    "\n",
    "## Beta Value\n",
    "\n",
    "$\\beta_a = \\frac{Cov(r_a,r_m)}{Var(r_m)}$\n",
    "\n",
    "beta = how risky your portfolio is relative to the market\n",
    "\n",
    "- If your portfolio has no risk: your expected return is the risk-free return\n",
    "\n",
    "- If your portfolio is more risky than the market: your expected return will be higher\n",
    "\n",
    "- If you portfolio is less rsky than the market: your expected return will be less\n",
    "\n",
    "We know how to calculate the $\\beta$ value for a single stock: \n",
    "- Just calculate the covariance between stock and market (SPY500) over the variance of the market\n",
    "$~~~\\beta_a = \\frac{Cov(r_a,r_m)}{Var(r_m)}$\n",
    "\n",
    "***How to deal with a portfolio containing several stocks?***\n",
    "\n",
    "A given portfolio's $\\beta$ beta value is the weighted sum of the stocks' betas within one portfolio\n",
    "<div style=\"text-align:center\"> $\\beta_a = w_1\\beta_1 + w_2\\beta_2 + \\cdots + w_n\\beta_n$ </div>\n",
    "\n",
    "The weights are the same as:\n",
    "\n",
    "\n",
    "    stock:     APPL   GOOGL   TSLA   GE\n",
    "    Precent:   20%    30%     25%    25%\n",
    "    Weight:    0.2    0.3     0.25   0.25\n",
    "    Weights = [0.2,0.3,0.25,0.25] = 1 (100%)\n",
    "\n",
    "$\\beta_a$ is a linear combination of $\\vec{b} \\cdot \\vec{w}$\n",
    "\\begin{equation}\n",
    "\\beta_a =\n",
    "         \\vec{b}=\\begin{bmatrix}\n",
    "             b_1 \\\\\n",
    "             b_2 \\\\\n",
    "             \\vdots\\\\\n",
    "             b_n\\\\\n",
    "            \\end{bmatrix}\n",
    "\\cdot\n",
    "         \\vec{w}=\\begin{bmatrix}\n",
    "             w_1 \\\\\n",
    "             w_2 \\\\\n",
    "             \\vdots\\\\\n",
    "             w_n\\\\\n",
    "            \\end{bmatrix}\n",
    "\\end{equation}\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Linear Regression w/ CAMP\n",
    "<img src=\"images/lin_regress.png\">\n",
    "<div style=\"text-align:center\"> $E[r_a] - r_f = \\alpha + \\beta(E[r_m]-r_f)$ </div>\n",
    "\n",
    "Beta is the only relevant measure of risk: determines the additional premium beyond the risk-free rate\n",
    "\n",
    "**What is $\\alpha$ alpha?**\n",
    "\n",
    "*alpha $\\alpha$* is the difference between the actual return and the expected return.\n",
    "\n",
    "<div style=\"text-align:center; color:red\"> $\\alpha = E[r_a] - (r_f  + \\beta(E[r_m]-r_f))$ </div>\n",
    "\n",
    "**For example:**\n",
    "    CAPM may estimate that a portfolio should return **15%**, but it actually earned **20%**. In this case alpha is the difference so **+5%**\n",
    "\n",
    "***FOR CAPM ALPHA IS ZERO!***\n",
    "\n",
    "\n",
    "***Why use monthly returns?***\n",
    "- use daily returns if you want to deal with microscopic data. For example holidays, etc.\n",
    "- Daily returns are best for superior sgort-term tactical forecasting\n",
    "- For long term models **monthly returns** are favourable. The main benefit is that with monthly data, returns are at least approximately normall distributed\n",
    "\n",
    "***Most of the models assume normal Distribution*** \n",
    "\n",
    "$\\beta = 0.5$ less volatile than the market\n",
    "\n",
    "- Stock market goes up by 10% -> this stock goes up by 5%\n",
    "- Stock market falls by 2% -> this stock falls by 1%\n",
    "\n",
    "$\\beta = 1.5$ 50% more volatile than the market\n",
    "\n",
    "- Stock market goes up by 10% -> this stock goes up by 15%\n",
    "- Stock market falls by 2% -> this stock falls by 3%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "$"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
